<template>
  <div class="nav-bar" :class="{ 'is_fixed': isFixed }">
    <div class="container">
      <div class="pro-title">小米8</div>
      <div class="pro-param">
        <a href="javascript:;">概述</a><span>|</span>
         <a href="javascript:;">参数</a><span>|</span>
        <a href="javascript:;">用户评价</a>
        <slot name="buy"></slot>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "nav-bar",
  data(){
      return{
         isFixed:0
      }
  },
  mounted(){
      //绑定window事件
      window.addEventListener('scroll',this.initHeight)
  },
  methods:{
     initHeight(){
         //获取Y轴的偏移量 
         let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop;
        //  true:false
         this.isFixed = scrollTop > 152 ? 1:0;
     }
  },
  destroyed () {
       window.removeEventListener('scroll',this.initHeight,false)
  }
};
</script>
<style lang="scss" scoped>
@import "./../assets/scss/config.scss";
@import "./../assets/scss/mixin.scss";
.nav-bar {
  z-index: 20;
  height: 70px;
  line-height: 70px;
  border-top: 1px solid #e5e5e5;
  background-color: $colorG;
 
  &.is_fixed{
      position: fixed;
      top: 0;
      width: 100%;
    box-shadow: 0 5px 5px $colorE;
  }
  .container {
    @include flex();
    .pro-title {
      font-size: 18px;
      color: $colorB;
      font-weight: bold;
    }
    .pro-param {
      font-size: 14px;
      span{
          margin: 0 10px;
      }
      a {
        color: $colorC;
    
      }
    }
  }
}
</style>